<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Card>
      <p slot="title">
        <Icon type="person"></Icon>
        测试页面
      </p>
      <div style="min-height: 380px;">
        <Form
          :model="addData"
          :label-width="200"
          label-position="right"
        >
          <FormItem label="附件：">
            <div style="display:inline-block;width:90%;" class="accessory feedback_add_accessory">
              <img v-for="el in addData.imagesArr" :src="el.url" class="img">
              <Upload
                :before-upload="handleUpload" action="" :format="format"
                :multiple="true">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
          <div style="padding-left: 200px;">
            <Button type="primary" style="width: 100px;" @click="saveInfoAjax">测试接口</Button>
          </div>
        </Form>
      </div>
    </Card>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import Nim from '../../libs/mod.nim';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  export default {
    name: 'test',
    data () {
      return {
        uid: '', // 登录用户的userId
        format: Util.constant.format,
        id: '',
        save_loading: false,
        addData: {
          content: '',
          anonymous: false,
          imagesArr: [],
        },
      };
    },
    mounted () {
      var _this = this;
    },
    methods: {
      // 保存
      saveInfoAjax () {
        var _this = this;
        // 接口参数
        var data = {
//          uid: Util.toJson(localStorage.getItem('userInfo')).id,
//          type: 'suggest',
          type: 'status',
          id: 22,
          status: 5 // 已发布
        };
        // 接口名
        var url = '/announcement/update';
        var params = {
          url: url,
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            console.log('成功=', res);

            _this.$Message.destroy();
            _this.$Message.success('成功!');
          } else {
            _this.$Message.destroy();
            _this.$Message.error('失败!');
          }
        }
      },
      // 选中文件
      handleUpload: function (file) {
        var _this = this;
        _this.UploadFile(file);
        return false;
      },
      // 上传文件
      UploadFile: function (file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var type = arr[arr.length - 1];
        var formData = new FormData();
        formData.append("file", file);
        formData.append("type", "image");
        var params = {
          url: '/attach/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            console.log('上传成功=', res);
            _this.$Message.destroy();
            _this.$Message.error('上传成功!');
          } else {
            _this.$Message.destroy();
            _this.$Message.error('上传失败!');
          }
        }
      },

    }
  };
</script>

